package com.gopay.solution.dao.smelly.impl;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.domain.cps.CpsProductLineInfo;
import com.gopay.solution.dao.smelly.CpsProductLineInfoTempDAO;

/**
 * @CpsProductLineInfoTempDAOImpl.java
 * @author MA HUAN
 * @2013-4-11 下午4:22:55 www.gopay.com.cn Inc.All rights reserved.
 */

@SuppressWarnings({ "rawtypes", "unchecked" })
@Repository(value = "cpsProductLineInfoTempDAO")
public class CpsProductLineInfoTempDAOImpl extends BaseDAOImpl<CpsProductLineInfo, Serializable> implements
        CpsProductLineInfoTempDAO {
    
    private static final String SEQUENCE_NAME = "S_CPS_PRODUCTLINE_INFO ";

    @Override
    public List<CpsProductLineInfo> listByProdLineName(String plName) {
        
        if(StringUtils.isEmpty(plName)) {
            return null;
        }

        String hql = " from CpsProductLineInfo cpli where cpli.prodLineName = :ProdLineName";

        Map params = new HashMap();
        params.put("ProdLineName", plName);

        List<CpsProductLineInfo> list = super.findByHql(hql, params);
        if (list != null && list.size() > 0) {
            return list;
        }
        return null;
    }

    @Override
    public String getProdLineId() {
        String seq = super.getNextId(SEQUENCE_NAME);
        DecimalFormat f = new DecimalFormat("0000000000");
        return f.format(Long.parseLong(seq));
    }

}
